package com.yanqu.road.server.cmd.activity.stronghold;

import com.yanqu.road.entity.activity.ActivityConditionInfo;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.ActivityRewardResult;
import com.yanqu.road.pb.activity.StrongholdWarProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.strongholdwar.StrongholdActivityModule;
import com.yanqu.road.server.manger.activity.strongholdwar.StrongholdActivityMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_STRONGHOLD_ACTIVITY_GET_RANK_REWARD,desc = "据点战领奖")
public class StrongholdActivityGetRewardCmd extends AbstractCommand {
    private int activityId;

    private int conditionId;

    private ActivityInfo activityInfo;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        StrongholdWarProto.StrongholdActivityGetRewardReqMsg reqMsg = StrongholdWarProto.StrongholdActivityGetRewardReqMsg.parseFrom(packet.getBytes());
        conditionId = reqMsg.getConditionId();
        activityId = reqMsg.getActivityId();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        activityInfo = StrongholdActivityMgr.getActivityInfo();
        if (activityInfo != null && StrongholdActivityMgr.isRewardTime()) {
            ActivityConditionInfo conditionInfo = StrongholdActivityMgr.getActivityConditionInfo(activityId, conditionId);
            if (conditionInfo != null) {
                ActivityRewardResult result = player.getModule(StrongholdActivityModule.class).sendCrossRankReward(activityId, conditionId, conditionInfo.getType());
                int ret = result.getRet();
                if (ret != 0) {
                    StrongholdWarProto.StrongholdActivityGetRewardRespMsg.Builder resp = StrongholdWarProto.StrongholdActivityGetRewardRespMsg.newBuilder();
                    resp.setRet(ret);
                    player.sendPacket(ClientProtocol.U_STRONGHOLD_ACTIVITY_GET_RANK_REWARD,resp);
                }
            }
        }
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
